package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

// 参数绑定(ShouldBind)

// Binding from JSON
type Login struct {
	User     string `form:"user" json:"user"`
	Password string `form:"password" json:"pwd"`
}

func main() {
	router := gin.Default()
	router.POST("/loginJSON", func(c *gin.Context) {
		var u Login
		err := c.ShouldBind(&u)
		if err != nil {
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		} else {
			fmt.Printf("login info:%#v\n", u)
			c.JSON(http.StatusOK, gin.H{
				"user":     u.User,
				"password": u.Password,
			})

		}
	})
	router.Run(":8080")
}
